package com.hy.appium1;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class AppiumDemo1IBOOK {

    AndroidDriver Driver;


    @BeforeMethod
    public void SetUp() throws MalformedURLException {
        //1.需要创建配置对象   desiredcapabilities
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        //将需要启动的软件的一些配置添加进来
        //1.添加需要测试 的主机的路径
        desiredCapabilities.setCapability("deviceName", "127.0.0.1:62001");
        desiredCapabilities.setCapability("platformName", "Android");
        desiredCapabilities.setCapability("appPackage", "com.iBookStar.activityOff");
        //默认启动不初始化软件
//        desiredCapabilities.setCapability("noReset", "true");
        desiredCapabilities.setCapability("appActivity", "com.iBookStar.activityOff.Splash");
        //创建驱动
//        AndroidDriver<WebElement> Driver = new AndroidDriver<WebElement>(url, desiredCapabilities);
        Driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
        Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void test() throws InterruptedException {


//com.iBookStar.activityOff:id/tab_indicator

        Driver.findElementById("com.iBookStar.activityOff:id/go").click();

        Thread.sleep(5000);

        Driver.findElementById("com.iBookStar.activityOff:id/cancel").click();

        Thread.sleep(5000);

        Driver.findElementById("com.iBookStar.activityOff:id/tab_indicator").click();
        Thread.sleep(5000);


//        Driver.swipe(600,400,100,400,800);



//        TouchAction touchAction = new TouchAction(Driver);
//
//        PointOption start = PointOption.point(600, 400);
//        PointOption end = PointOption.point(100, 400);
//
//        Duration duration = Duration.ofMillis(8000);
//
//        WaitOptions waitOptions = WaitOptions.waitOptions(duration);
//
//        touchAction.press(start).waitAction(waitOptions).moveTo(end).release();
//
//        touchAction.perform();
//        Thread.sleep(5000);
//
//        touchAction.press(start).waitAction(waitOptions).moveTo(end).release();
//
//        touchAction.perform();


        //Driver.Swipe(开始坐标的X轴，Y轴，结束坐标的X轴，Y轴);

    }

    @AfterMethod
    public void TestDown() {
//        Driver.quit();
    }
}
